// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:intl/intl.dart';
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/status.dart' as status;

void main() {
  final channel = IOWebSocketChannel.connect('ws://192.168.110.41:8765');
  channel.sink.add("qwq");
  // 连接成功后，开始监听用户输入并发送消息到服务器
  stdin.listen((data) {
    String message = String.fromCharCodes(data).trim();
    if (message.toLowerCase() == 'exit') {
      channel.sink.close();
      exit(0);
    } else {
      channel.sink.add(message);
    }
  });

  // 监听从服务器接收的消息并打印
  channel.stream.listen((message) {
    print('$message');
  });

  print('连接完成,开始聊天吧！');
}